//
//  AutoInfoView.m
//  Project_B
//
//  Created by 甘霞 on 15/11/24.
//  Copyright © 2015年 Atom_Wang. All rights reserved.
//

#import "AutoInfoView.h"
#import "Masonry.h"

@interface AutoInfoView ()

@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIImageView *autorImageView;
@property (nonatomic, retain) UILabel *authorName;
@property (nonatomic, retain) UILabel *subTitleLabel;
@property (nonatomic, retain) UIImageView *pageImageView;
@property (nonatomic, retain) UILabel *pageLabel;

@end

@implementation AutoInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    //标题
    self.titleLabel = [[UILabel alloc] init];
    [self addSubview:self.titleLabel];
    [self.titleLabel setNumberOfLines:2];
    [self.titleLabel setTextColor:[UIColor whiteColor]];
    [self.titleLabel setFont:[UIFont systemFontOfSize:kTitleFontSize]];
    
    //副标题
    self.subTitleLabel = [[UILabel alloc] init];
    [self addSubview:self.subTitleLabel];
    [self.subTitleLabel setNumberOfLines:3];
    [self.subTitleLabel setTextColor:[UIColor whiteColor]];
    [self.subTitleLabel setFont:[UIFont systemFontOfSize:kSubTitleFontSize]];
    
    //作者头像
    self.autorImageView = [[UIImageView alloc] init];
    [self addSubview:self.autorImageView];
    
    //作者名字
    self.authorName = [[UILabel alloc] init];
    [self addSubview:self.authorName];
    [self.authorName setTextColor:[UIColor whiteColor]];
    [self.authorName setFont:[UIFont systemFontOfSize:kSubTitleFontSize]];
    
    //页码图片
    self.pageImageView = [[UIImageView alloc] init];
    [self.pageImageView setImage:[UIImage imageNamed:@"icon-pagersign"]];
    [self addSubview:self.pageImageView];
    
    //页码
    self.pageLabel = [[UILabel alloc] init];
    [self.pageLabel setTextColor:[UIColor whiteColor]];
    [self addSubview:self.pageLabel];
}

- (void)layoutSubviews {
    //文本宽度
    CGFloat labelW = self.frame.size.width - kPageImageSize - 3 * kAutoSideBorder;
    //标题
    [self.titleLabel setFrame:CGRectMake(kAutoSideBorder, 80, labelW, 100)];
    //作者头像
    [self.autorImageView setFrame:CGRectMake(kAutoSideBorder, 180, kAuthorImageViewSize, kAuthorImageViewSize)];
    self.autorImageView.layer.cornerRadius = kAuthorImageViewSize / 2;

    self.autorImageView.layer.masksToBounds = YES;
    //作者名字
    [self.authorName setFrame:CGRectMake(kAutoSideBorder + 40, 180, labelW, 30)];
    //副标题
    [self.subTitleLabel setFrame:CGRectMake(kAutoSideBorder, 210,  labelW, 80)];
    //页码图片
    [self.pageImageView setFrame:CGRectMake(kAutoSideBorder + labelW + 10, 230, kPageImageSize, kPageImageSize)];
    //页码
    [self.pageLabel setFrame:CGRectMake(0, 0, 30, 30)];
    self.pageLabel.center = self.pageImageView.center;
}

@end
